package cn.com.wxd.wechat.common.util.crypto;

import cn.com.wxd.common.security.SHA1Util;

import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

/**
 * Created by on 14/10/19.
 */
public class SHA1 {

	/**
	 * 串接arr参数，生成sha1 digest
	 * @param arr
	 * @return
	 */
	public static String gen(String... arr) throws NoSuchAlgorithmException {
		Arrays.sort(arr);
		StringBuilder sb = new StringBuilder();
		for (String a : arr) {
			sb.append(a);
		}
		SHA1Util su = new SHA1Util();
		return su.getDigestOfString(sb.toString().getBytes());
	}
	

	/**
	 * 用&串接arr参数，生成sha1 digest
	 * @param arr
	 * @return
	 */
	public static String genWithAmple(String... arr) throws NoSuchAlgorithmException {
		Arrays.sort(arr);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < arr.length; i++) {
			String a = arr[i];
			sb.append(a);
			if (i != arr.length - 1) {
				sb.append('&');
			}
		}
		SHA1Util su = new SHA1Util();
		return su.getDigestOfString(sb.toString().getBytes());
	}
}
